package LexicalAnalyzer;

/**
 *  integer:  a sequence of 1 or more decimal digits.  The maximum value of an integer constant is 2147483648.
    hex integer:  0x followed by a sequence of 1 or more hex digits
    real:  Consists of an integer part, a decimal point, a fraction part, an e or E, and an optionally signed integer exponent.  
    Either the integer part or the fraction part (but not both) may be missing; either the decimal point or the e and exponent (but not both) may be missing.

 * @author vcolegro, akanter
 *
 */
public class Constant extends Token{
	//Types   6: real; 7: hex; 8: digit
	
	/**
	 * 
	 * @param s String with constant in it
	 */
	public Constant(String s, int type) throws RuntimeException {
		super("");
		this.type=type;
		
		if (type ==8){ 
			setContent("num("+s+")");
		}
		else if (type ==7){
			setContent("hex("+s+")");
		}
		else if (type ==6){
			setContent("real("+s+")");
		}
		//Shouldn't ever get here
		else{
			setContent("Error: Invalid number");
			throw new RuntimeException("Invalid number");
		}
	}
	
	public String getContent(){
		if(!content.contains("(")){
			return content;
		}
		return content.substring(0, content.indexOf('('));
	}

}
